﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;
using System.Windows.Forms;
using System.Collections;

using System.Drawing;

namespace Quadarax.Applications.ASMIDE.Controls
{
    public class QSourceEdit : Control 
    {

        private string m_sFileName = "";
        private bool m_bIsLineNumber = false;
        private bool m_bIsChanged = false;

        private QTextCacheCollection m_oCache = new QTextCacheCollection();

        private long m_nVisibleMinRowPostition = 0;
        private long m_nVisibleMaxRowPostition = 0;
        private long m_nVisibleCurrentRowPostition = 0;


        private bool m_bWrapText = false;
        private int m_nRowsPerVisibleArea = 0;

        public string FileName
        {
            get
            {
                return m_sFileName;
            }
            set
            {
                m_sFileName = value;
                Open();
            }
        }


        public bool IsLineNumber
        {
            get
            {
                return m_bIsLineNumber;
            }
            set
            {
                m_bIsLineNumber = value;
            }
        }


        public QSourceEdit()
            : base()
        {
            InitInternal();
        }


        protected virtual void InitInternal()
        {
            this.BackColor = System.Drawing.Color.White;
            this.Cursor = Cursors.IBeam;
        }


        public void Open()
        {
            Open(m_sFileName);
        }


        public void Open(string sFileName)
        {
            if (sFileName.Length > 0)
            {
                m_oCache.Init(QTextCacheCollection.eMeasurement.cnmParagraph,sFileName, 10);
                Refresh();
            }
            m_oCache.Dump();            
        }

        //public void Open(FileStream oFileStream)
        //{
        //    byte[] aBuffer = new byte[1024];
        //    oFileStream.Read(aBuffer, 0, 1024);            
        //    m_oCache.Init(oFileStream,
        //   // m_oCache.Add(new QTextCache(oEnc.GetString(aBuffer)));
        //}

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            //for (int a = 0; a < m_oCache.Count; a++)
            //{
            //    int b = 0;
            //    //e.Graphics.DrawString(m_oCache[a].Data, this.Font, SystemBrushes.FromSystemColor(this.ForeColor), 0, 0);
            //}
        }

        public override void Refresh()
        {
                        
            base.Refresh();
        }
    }
}
